//
//  AppDelegate.m
//  iNews
//
//  Created by lanou3g on 14-12-4.
//  Copyright (c) 2014年 张在青. All rights reserved.
//

#import "AppDelegate.h"

#import "RootTabBarController.h"

#import "MobClick.h"
#import "UMSocial.h"
#import "NetRequest.h"
#import "Reachability.h"
#import "movieHandel.h"
@implementation AppDelegate


- (void)dealloc
{
    [_window release];

    [super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
   
//    self.net = YES;
//    [self setNetnot];
    
    RootTabBarController *rootTBC = [[[RootTabBarController alloc] init] autorelease];
    self.window.rootViewController = rootTBC;
    
    //-------------------------------------------------------------------------------
    [MobClick setLogEnabled:YES];
    
    //加入友盟统计
    //第一个参数,是在友盟开发平台注册的本App的appid
    //第二个参数,是数据发送机制,枚举值
    //第三个参数,是推广平台,@""默认为app store
    [MobClick startWithAppkey:@"537bfc9456240b066602f82b" reportPolicy:BATCH channelId:@""];
    
    [MobClick updateOnlineConfig];
    //获取app版本
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    
   // NSLog(@"version:%@",version);
    [MobClick setAppVersion:version];
    
    
    //-------------------------------------------------------------------------------
    
    [UMSocialData setAppKey:@"537bfc9456240b066602f82b"];
    
    
    [UMSocialConfig setShouldCommentWithShare:NO];
    
    //打开新浪微博的SSO开关
    [UMSocialConfig setSupportSinaSSO:YES appRedirectUrl:@"http://sns.whalecloud.com/sina2/callback"];
    
    //打开人人网的sso开关
    
    //设置微信AppId，设置分享url，默认使用友盟的网址
        //[UMSocialWechatHandler setWXAppId:@"wxd9a39c7122aa6516" url:@"http://www.umeng.com/social"];
    
    
       // [UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];
    
    //
    //    //设置分享到QQ空间的应用Id，和分享url 链接
      //  [UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"c7394704798a158208a74ab60104f0ba" url:@"http://www.umeng.com/social"];
    //    [UMSocialQQHandler setSupportQzoneSSO:YES];
    //
    //    //设置易信Appkey和分享url地址
    //    [UMSocialYixinHandler setYixinAppKey:@"yx35664bdff4db42c2b7be1e29390c1a06" url:@"http://www.umeng.com/social"];
    //
    //    //设置来往AppId，appscret，显示来源名称和url地址
    //    [UMSocialLaiwangHandler setLaiwangAppId:@"8112117817424282305" appSecret:@"9996ed5039e641658de7b83345fee6c9" appDescription:@"友盟社会化组件" urlStirng:@"http://www.umeng.com/social"];
    //
    

    //网络监测通知中心

    
    //[[movieHandel movieshareData] setNetnot];
   // [[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:nil];

    
    
    
    [self.window makeKeyAndVisible];
    return YES;
}

-(void)setNetnot{
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    
    hostReach = [[Reachability reachabilityWithHostName:@"www.baidu.com"] retain];
    [hostReach startNotifier];  //开始监听，会启动一个run loop
    
}


//网络链接改变时会调用的方法
-(void)reachabilityChanged:(NSNotification *)note
{
    Reachability *currReach = [note object];
    NSParameterAssert([currReach isKindOfClass:[Reachability class]]);
    
    //对连接改变做出响应处理动作
    NetworkStatus status = [currReach currentReachabilityStatus];
    //如果没有连接到网络就弹出提醒实况
    if(status == NotReachable)
    {
        NSLog(@"网络异常");
        // _netYes = NO;
        _net = NO;
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络异常" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [alert show];
        [alert dismissWithClickedButtonIndex:0 animated:YES];
        [alert release];
    }
    else
    {
        NSLog(@"网络正常");
        // _netYes = YES;
        _net = YES;
    }
}







/**
 这里处理新浪微博SSO授权之后跳转回来，和微信分享完成之后跳转回来
 */
//- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
//{
//    return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
//}


- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

/**
 这里处理新浪微博SSO授权进入新浪微博客户端后进入后台，再返回原来应用
 */
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    
    //[UMSocialSnsService  applicationDidBecomeActive];

}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
